package com.mxl.rabbitmq.consumer;

import com.mxl.rabbitmq.config.DlxConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalTime;

/**
 * 死信队列 消费者
 *
 * @author MXL
 * @date 2022/2/7
 **/
@Component
@Slf4j
public class DlxConsumer {

    @RabbitListener(queues = DlxConfig.DLX_QUEUE_NAME)
    public void handle(Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        log.info("死信队列: 时间: {}, 内容: {}", LocalTime.now());
        channel.basicAck(deliveryTag, false);
    }
}
